package com.sdy.healthcode.biz.mapper;

import com.sdy.healthcode.biz.dto.CodeCount;
import com.sdy.healthcode.biz.dto.HealthCodeAnalyze;
import com.sdy.healthcode.biz.model.HealthCode;
import com.sdy.mvc.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zzq
 * @since 2020-02-18
 */
public interface HealthCodeMapper extends BaseMapper<HealthCode> {
    @Select("select count(*) as counts, hcode from (\n" +
            "select s1.* from health_code s1\n" +
            "left join user s2 on s2.id = s1.user_id\n" +
            "where s1.state = 1 and (s2.region_province = #{areaCode} or s2.region_city = #{areaCode} or s2.region_area = #{areaCode})\n" +
            ") s group by hcode;")
    List<CodeCount> getCodeCount(@Param("areaCode") String areaCode);

    @Select("select \n" +
            "p1.hcode,ifnull(count(p2.user_id),0) num\n" +
            "from (\n" +
            "select 'G' hcode\n" +
            "union \n" +
            "select 'Y' hcode\n" +
            "union \n" +
            "select 'R' hcode\n" +
            ") p1\n" +
            "left join \n" +
            "health_code p2\n" +
            "on p1.hcode=p2.hcode\n" +
            "and p2.type=3\n" +
            "and p2.state=1\n" +
            "group by p1.hcode")
    List<Map<String,Object>> getHospitalNum();
}
